﻿@model NewsletterBoxModel
@using Nop.Web.Models.Newsletter;
<div class="block block-newsletter" id="sh-footer-subscribe-block">
    <h3>Subscribe to Our Newsletter</h3>
    <p>Subscribe to our newsletter</p>

    <div id="newsletter-subscribe-block">
        <form id="footer-subscribe-form">
            @Html.TextBoxFor(x => x.NewsletterEmail, new { id = "subscribe-text",  placeholder = "Enter your Email..."})
            @Html.ValidationMessageFor(x => x.NewsletterEmail)
            <input id="newsletter-subscribe" type="hidden" name="newsletter-subscribe" value="newsletter-subscribe" /> <br />
            <input type="button" value="@T("Newsletter.Button")" id="subscribe-submit" class="button-1 newsletter-subscribe-button" />
            <span id="subscribe-loading-progress" style="display: none;">@T("Common.Wait...")
                <img src='@Url.Content("~/subsites/Commerce/Content/Images/ajax_loader_small.gif")' alt="@T("Common.Wait...")" />
            </span>
        </form>
     </div>
    <div id="newsletter-result-block"></div>

    <script type="text/javascript">
        $(document).ready(function () {
            $('#subscribe-submit').click(function () {
                showNotification();
                var subscribe = 'true';
                var email = $("#subscribe-text").val();
                
                $.ajax({
                    cache: false,
                    type: "POST",
                    url: "@(Url.RouteUrl("SubscribeNewsletter"))",
                    data: { "subscribe": subscribe, "email": email },
                    success: function (data) {
                        if (data.Success) {
                            callbackNotification(data.Result, 'Thank you!');
                            $("#subscribe-text").val('');
                        }
                        else {
                            callbackNotification(data.Result, 'Notice');
                        }
                    },
                    error: function (xhr, ajaxOptions, thrownError){
                        callbackNotification('Unable to subscribe at the moment. Please check back later!', 'Connection Error!');
                    }  
                });                
                return false;
            });
        });
    </script>
</div>
